<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Freetype OpenGL: demo-atb-agg.c</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="style.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="content"><!-- do not remove this div! -->

<div id="top"><!-- do not remove this div! -->

  
  <div id="titlearea">
    
    <div id="projectname">Freetype OpenGL</div>
    
    
    <div id="projectbrief">A high quality OpenGL text rendering engine for C</div>
    
  </div>
  

<!--

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Freetype OpenGL
   &#160;<span id="projectnumber">0.1</span>
   </div>
   <div id="projectbrief">A high quality OpenGL text rendering engine for C</div>
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>
-->


<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">demo-atb-agg.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="comment">/* ============================================================================</span>
<span class="comment"> * Freetype GL - A C OpenGL Freetype engine</span>
<span class="comment"> * Platform:    Any</span>
<span class="comment"> * WWW:         http://code.google.com/p/freetype-gl/</span>
<span class="comment"> * ----------------------------------------------------------------------------</span>
<span class="comment"> * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.</span>
<span class="comment"> *</span>
<span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<span class="comment"> *</span>
<span class="comment"> *  1. Redistributions of source code must retain the above copyright notice,</span>
<span class="comment"> *     this list of conditions and the following disclaimer.</span>
<span class="comment"> *</span>
<span class="comment"> *  2. Redistributions in binary form must reproduce the above copyright</span>
<span class="comment"> *     notice, this list of conditions and the following disclaimer in the</span>
<span class="comment"> *     documentation and/or other materials provided with the distribution.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER &#39;&#39;AS IS&#39;&#39; AND ANY EXPRESS OR</span>
<span class="comment"> * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span>
<span class="comment"> * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO</span>
<span class="comment"> * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,</span>
<span class="comment"> * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<span class="comment"> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<span class="comment"> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
<span class="comment"> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF</span>
<span class="comment"> * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<span class="comment"> *</span>
<span class="comment"> * The views and conclusions contained in the software and documentation are</span>
<span class="comment"> * those of the authors and should not be interpreted as representing official</span>
<span class="comment"> * policies, either expressed or implied, of Nicolas P. Rougier.</span>
<span class="comment"> * ============================================================================</span>
<span class="comment"> */</span>
<span class="preprocessor">#include &lt;AntTweakBar.h&gt;</span>
<span class="preprocessor">#include &quot;freetype-gl.h&quot;</span>

<span class="preprocessor">#include &quot;<a class="code" href="font-manager_8h.html">font-manager.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="vertex-buffer_8h.html">vertex-buffer.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="text-buffer_8h.html">text-buffer.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="markup_8h.html">markup.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="shader_8h.html">shader.h</a>&quot;</span>


<span class="comment">// ------------------------------------------------------- typedef &amp; struct ---</span>
<span class="keyword">typedef</span> <span class="keyword">enum</span> {
    VERA = 1,
    VERA_MONO,
    GEORGIA,
    TIMES,
    VERDANA,
    TAHOMA,
    ARIAL,
} font_family_e;

<span class="preprocessor">#define NUM_FONTS 7</span>
<span class="preprocessor"></span>
<span class="keyword">typedef</span> <span class="keyword">struct </span>{
    <span class="keywordtype">float</span> x, y, z;
    <span class="keywordtype">float</span> s, t;
    <span class="keywordtype">float</span> r, g, b, a;
    <span class="keywordtype">float</span> m;
} vertex_t;


<span class="comment">// ------------------------------------------------------- global variables ---</span>
TwBar *bar;
<a name="_a0"></a><a class="code" href="structvertex__buffer__t.html" title="Generic vertex buffer.">vertex_buffer_t</a> * buffer;
<a name="_a1"></a><a class="code" href="structtexture__atlas__t.html" title="A texture atlas is used to pack several small regions into a single texture.">texture_atlas_t</a> * atlas_gray, * atlas_rgb, * atlas;
GLuint program = 0;
GLuint texture_location;
GLuint pixel_location;
GLuint gamma_location;
GLuint primary_location;
GLuint secondary_location;
GLuint tertiary_location;

font_family_e p_family;
<span class="keywordtype">float</span> p_size;
<span class="keywordtype">int</span> p_invert;
<span class="keywordtype">int</span> p_kerning;
<span class="keywordtype">int</span> p_hinting;
<span class="keywordtype">int</span> p_lcd_filtering;
<span class="keywordtype">float</span> p_gamma;
<span class="keywordtype">float</span> p_interval;
<span class="keywordtype">float</span> p_weight;
<span class="keywordtype">float</span> p_width;
<span class="keywordtype">float</span> p_faux_weight;
<span class="keywordtype">float</span> p_faux_italic;
<span class="keywordtype">float</span> p_primary;
<span class="keywordtype">float</span> p_secondary;
<span class="keywordtype">float</span> p_tertiary;

<span class="keyword">static</span> <span class="keywordtype">wchar_t</span> text[] = 
    L<span class="stringliteral">&quot;A single pixel on a color LCD is made of three colored elements \n&quot;</span>
    L<span class="stringliteral">&quot;ordered (on various displays) either as blue, green, and red (BGR), \n&quot;</span>
    L<span class="stringliteral">&quot;or as red, green, and blue (RGB). These pixel components, sometimes \n&quot;</span>
    L<span class="stringliteral">&quot;called sub-pixels, appear as a single color to the human eye because \n&quot;</span>
    L<span class="stringliteral">&quot;of blurring by the optics and spatial integration by nerve cells in &quot;</span>
    L<span class="stringliteral">&quot;the eye.\n&quot;</span>
    L<span class="stringliteral">&quot;\n&quot;</span>
    L<span class="stringliteral">&quot;The resolution at which colored sub-pixels go unnoticed differs, \n&quot;</span>
    L<span class="stringliteral">&quot;however, with each user some users are distracted by the colored \n&quot;</span>
    L<span class="stringliteral">&quot;\&quot;fringes\&quot; resulting from sub-pixel rendering. Subpixel rendering \n&quot;</span>
    L<span class="stringliteral">&quot;is better suited to some display technologies than others. The \n&quot;</span>
    L<span class="stringliteral">&quot;technology is well-suited to LCDs, but less so for CRTs. In a CRT \n&quot;</span>
    L<span class="stringliteral">&quot;the light from the pixel components often spread across pixels, \n&quot;</span>
    L<span class="stringliteral">&quot;and the outputs of adjacent pixels are not perfectly independent.&quot;</span>
    L<span class="stringliteral">&quot;\n&quot;</span>;



<span class="comment">// -------------------------------------------------------------- add_glyph ---</span>
<span class="keywordtype">void</span> add_glyph( <span class="keyword">const</span> <a name="_a2"></a><a class="code" href="structtexture__glyph__t.html" title="A structure that describe a glyph.">texture_glyph_t</a> * glyph,
                <a class="code" href="structvertex__buffer__t.html" title="Generic vertex buffer.">vertex_buffer_t</a> * buffer,
                <span class="keyword">const</span> <a name="_a3"></a><a class="code" href="structmarkup__t.html" title="Simple structure that describes text properties.">markup_t</a> * markup,
                <a name="_a4"></a><a class="code" href="unionvec2.html" title="Tuple of 2 floats.">vec2</a> *pen, <span class="keywordtype">float</span> kerning )
{
    <span class="keywordflow">if</span>( p_kerning )
    {
        pen-&gt;<a name="a5"></a><a class="code" href="unionvec2.html#a002d3519d48fe3cd79729b5b0ded74bf" title="Alias for first component.">x</a> += kerning;
    }
    <span class="keywordflow">else</span>
    {
    }

    <span class="keywordtype">float</span> r = markup-&gt;<a name="a6"></a><a class="code" href="structmarkup__t.html#a04c930fd29432569aee47e56b59e3d79" title="Text color.">foreground_color</a>.<a name="a7"></a><a class="code" href="unionvec4.html#a1682827e4304b44e6f768d616cdf3899" title="Alias for first component.">r</a>;
    <span class="keywordtype">float</span> g = markup-&gt;<a class="code" href="structmarkup__t.html#a04c930fd29432569aee47e56b59e3d79" title="Text color.">foreground_color</a>.<a name="a8"></a><a class="code" href="unionvec4.html#aa626a2728056a1b410fb8e133bdffd05" title="Alias fo second component.">g</a>;
    <span class="keywordtype">float</span> b = markup-&gt;<a class="code" href="structmarkup__t.html#a04c930fd29432569aee47e56b59e3d79" title="Text color.">foreground_color</a>.<a name="a9"></a><a class="code" href="unionvec4.html#a62421478df6548c8e5e24d33345e3417" title="Alias fo third component.">b</a>;
    <span class="keywordtype">float</span> a = markup-&gt;<a class="code" href="structmarkup__t.html#a04c930fd29432569aee47e56b59e3d79" title="Text color.">foreground_color</a>.<a name="a10"></a><a class="code" href="unionvec4.html#ac1c847c2cd65c10fd059fceb8e57a5f6" title="Alias fo fourth component.">a</a>;
    <span class="keywordtype">float</span> x0  = ( pen-&gt;<a class="code" href="unionvec2.html#a002d3519d48fe3cd79729b5b0ded74bf" title="Alias for first component.">x</a> + glyph-&gt;<a name="a11"></a><a class="code" href="structtexture__glyph__t.html#a1f267cdba6bd1aff244ff72792ab1a38" title="Glyph&#39;s left bearing expressed in integer pixels.">offset_x</a> );
    <span class="keywordtype">float</span> y0  = (int)( pen-&gt;<a name="a12"></a><a class="code" href="unionvec2.html#a6d28b12b511da692550fc9d37b4e9b1d" title="Alias for second component.">y</a> + glyph-&gt;<a name="a13"></a><a class="code" href="structtexture__glyph__t.html#aeacd07f592dfa953f26b2e5c1863a814" title="Glyphs&#39;s top bearing expressed in integer pixels.">offset_y</a> );
    <span class="keywordtype">float</span> x1  = ( x0 + glyph-&gt;<a name="a14"></a><a class="code" href="structtexture__glyph__t.html#a51379921bd46b454fc56b7d28381af03" title="Glyph&#39;s width in pixels.">width</a> * p_width );
    <span class="keywordtype">float</span> y1  = (int)( y0 - glyph-&gt;<a name="a15"></a><a class="code" href="structtexture__glyph__t.html#a7a0e2fc48006cf6815e5b1e7dae8d386" title="Glyph&#39;s height in pixels.">height</a> );

    <span class="keywordtype">float</span> s0 = glyph-&gt;<a name="a16"></a><a class="code" href="structtexture__glyph__t.html#adcfb6e5a1b583f96c96d87b006667f2b" title="First normalized texture coordinate (x) of top-left corner.">s0</a>;
    <span class="keywordtype">float</span> t0 = glyph-&gt;<a name="a17"></a><a class="code" href="structtexture__glyph__t.html#ab2fec7dd584f5cfaf14c3b8a807d5e70" title="Second normalized texture coordinate (y) of top-left corner.">t0</a>;
    <span class="keywordtype">float</span> s1 = glyph-&gt;<a name="a18"></a><a class="code" href="structtexture__glyph__t.html#a3849b83a8bb51a6fc32ce77b485d9e95" title="First normalized texture coordinate (x) of bottom-right corner.">s1</a>;
    <span class="keywordtype">float</span> t1 = glyph-&gt;<a name="a19"></a><a class="code" href="structtexture__glyph__t.html#aee3ba35a29e1646df9cfaca6c0db3488" title="Second normalized texture coordinate (y) of bottom-right corner.">t1</a>;
    GLuint index = buffer-&gt;<a name="a20"></a><a class="code" href="structvertex__buffer__t.html#a54efd077fb2990b3679d060baaa021ec" title="Vector of vertices.">vertices</a>-&gt;<a name="a21"></a><a class="code" href="structvector__t.html#a7ec97862387465722f8f08f8f8f69371" title="Number of items.">size</a>;
    GLuint indices[] = {index, index+1, index+2,
                        index, index+2, index+3};
    <span class="keywordtype">float</span> dx = tan(p_faux_italic/180.0 * M_PI) * (glyph-&gt;<a class="code" href="structtexture__glyph__t.html#a7a0e2fc48006cf6815e5b1e7dae8d386" title="Glyph&#39;s height in pixels.">height</a>);
    vertex_t vertices[] = { { (int)(x0+dx),y0,0,  s0,t0,  r,g,b,a,  x0+dx-((int)(x0+dx)) },
                            { (int)(x0   ),y1,0,  s0,t1,  r,g,b,a,  x0-((int)x0) },
                            { (int)(x1   ),y1,0,  s1,t1,  r,g,b,a,  x1-((int)x1) },
                            { (int)(x1+dx),y0,0,  s1,t0,  r,g,b,a,  x1+dx-((int)(x1+dx)) } };
    vertex_buffer_push_back_indices( buffer, indices, 6 );
    vertex_buffer_push_back_vertices( buffer, vertices, 4 );
    pen-&gt;<a class="code" href="unionvec2.html#a002d3519d48fe3cd79729b5b0ded74bf" title="Alias for first component.">x</a> += glyph-&gt;<a name="a22"></a><a class="code" href="structtexture__glyph__t.html#aba3ece1130e9d96562a5c2ec3e60da4c" title="For horizontal text layouts, this is the horizontal distance (in fractional pixels) used to increment...">advance_x</a> * (1.0 + p_interval);
    pen-&gt;<a class="code" href="unionvec2.html#a6d28b12b511da692550fc9d37b4e9b1d" title="Alias for second component.">y</a> += glyph-&gt;<a name="a23"></a><a class="code" href="structtexture__glyph__t.html#a1e13821e9ea8332f828ebb95aeefac06" title="For vertical text layouts, this is the vertical distance (in fractional pixels) used to increment the...">advance_y</a>;
}

<span class="comment">// ----------------------------------------------------------- build_buffer ---</span>
<span class="keywordtype">void</span>
build_buffer( <span class="keywordtype">void</span> )
{ 
    <a class="code" href="unionvec2.html" title="Tuple of 2 floats.">vec2</a> pen;
    <span class="keywordtype">size_t</span> i;
    <a name="_a24"></a><a class="code" href="structtexture__font__t.html" title="Texture font structure.">texture_font_t</a> *font;
    <a class="code" href="structtexture__glyph__t.html" title="A structure that describe a glyph.">texture_glyph_t</a> *glyph;

    <a name="_a25"></a><a class="code" href="unionvec4.html" title="Tuple of 4 floats.">vec4</a> white  = {{1.0, 1.0, 1.0, 1.0}};
    <a class="code" href="unionvec4.html" title="Tuple of 4 floats.">vec4</a> none   = {{1.0, 1.0, 1.0, 0.0}};
    <a class="code" href="structmarkup__t.html" title="Simple structure that describes text properties.">markup_t</a> markup = {
        .<a name="a26"></a><a class="code" href="structmarkup__t.html#adcb67782935faf6178ef7afde350ca2a" title="A font family name such as &quot;normal&quot;, &quot;sans&quot;, &quot;serif&quot; or &quot;monospace&quot;.">family</a>  = <span class="stringliteral">&quot;Arial&quot;</span>,
        .size    = 10.0,
        .bold    = 0,
        .italic  = 0,
        .rise    = 0.0,
        .spacing = 0.0,
        .gamma   = 2.2,
        .foreground_color    = white,
        .background_color    = none,
        .underline           = 0,
        .underline_color     = white,
        .overline            = 0,
        .overline_color      = white,
        .strikethrough       = 0,
        .strikethrough_color = white,
        .font = 0,
    };



    <a name="a27"></a><a class="code" href="group__vertex-buffer.html#ga5a1c907e3e66b12be0c142e6d03acdaf" title="Clear all items.">vertex_buffer_clear</a>( buffer );
    <a name="a28"></a><a class="code" href="group__texture-atlas.html#gafc00ed05e30dd34ed70f6d775e441845" title="Remove all allocated regions from the atlas.">texture_atlas_clear</a>( atlas );

    <span class="keywordflow">if</span>( p_family == VERA)
    {
        font = <a name="a29"></a><a class="code" href="group__texture-font.html#ga904424e7b0e2be14b694599b5c483e64" title="This function creates a new texture font from given filename and size.">texture_font_new</a>( atlas, <span class="stringliteral">&quot;fonts/Vera.ttf&quot;</span>, p_size );
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( p_family == VERA_MONO)
    {
        font = <a class="code" href="group__texture-font.html#ga904424e7b0e2be14b694599b5c483e64" title="This function creates a new texture font from given filename and size.">texture_font_new</a>( atlas, <span class="stringliteral">&quot;fonts/VeraMono.ttf&quot;</span>, p_size );
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( p_family == GEORGIA)
    {
        font = <a class="code" href="group__texture-font.html#ga904424e7b0e2be14b694599b5c483e64" title="This function creates a new texture font from given filename and size.">texture_font_new</a>( atlas, <span class="stringliteral">&quot;fonts/Georgia.ttf&quot;</span>, p_size );
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( p_family == TIMES )
    {
        font = <a class="code" href="group__texture-font.html#ga904424e7b0e2be14b694599b5c483e64" title="This function creates a new texture font from given filename and size.">texture_font_new</a>( atlas, <span class="stringliteral">&quot;fonts/Times.ttf&quot;</span>, p_size );
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( p_family == TAHOMA )
    {
        font = <a class="code" href="group__texture-font.html#ga904424e7b0e2be14b694599b5c483e64" title="This function creates a new texture font from given filename and size.">texture_font_new</a>( atlas, <span class="stringliteral">&quot;fonts/Tahoma.ttf&quot;</span>, p_size );
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( p_family == ARIAL )
    {
        font = <a class="code" href="group__texture-font.html#ga904424e7b0e2be14b694599b5c483e64" title="This function creates a new texture font from given filename and size.">texture_font_new</a>( atlas, <span class="stringliteral">&quot;fonts/Arial.ttf&quot;</span>, p_size );
    }
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( p_family == VERDANA )
    {
        font = <a class="code" href="group__texture-font.html#ga904424e7b0e2be14b694599b5c483e64" title="This function creates a new texture font from given filename and size.">texture_font_new</a>( atlas, <span class="stringliteral">&quot;fonts/Verdana.ttf&quot;</span>, p_size );
    }
    <span class="keywordflow">else</span>
    {
        fprintf( stderr, <span class="stringliteral">&quot;Error : Unknown family type\n&quot;</span> );
        <span class="keywordflow">return</span>;
    }

    font-&gt;<a name="a30"></a><a class="code" href="structtexture__font__t.html#a0539f19037c06a115b0ff441e66449a9" title="Whether to use autohint when rendering font.">hinting</a> = p_hinting;
    font-&gt;<a name="a31"></a><a class="code" href="structtexture__font__t.html#a2fd58e98976e3985b1ed06f6e08299bf" title="Whether to use our own lcd filter.">filtering</a> = 1;
    <span class="keywordtype">float</span> norm = 1.0/(p_primary + 2*p_secondary + 2*p_tertiary);
    font-&gt;<a name="a32"></a><a class="code" href="structtexture__font__t.html#a6d2347450ec91e7148d211b21aed05d4" title="LCD filter weights.">lcd_weights</a>[0] = (<span class="keywordtype">unsigned</span> char)(p_tertiary*norm*256);
    font-&gt;<a class="code" href="structtexture__font__t.html#a6d2347450ec91e7148d211b21aed05d4" title="LCD filter weights.">lcd_weights</a>[1] = (<span class="keywordtype">unsigned</span> char)(p_secondary*norm*256);
    font-&gt;<a class="code" href="structtexture__font__t.html#a6d2347450ec91e7148d211b21aed05d4" title="LCD filter weights.">lcd_weights</a>[2] = (<span class="keywordtype">unsigned</span> char)(p_primary*norm*256);
    font-&gt;<a class="code" href="structtexture__font__t.html#a6d2347450ec91e7148d211b21aed05d4" title="LCD filter weights.">lcd_weights</a>[3] = (<span class="keywordtype">unsigned</span> char)(p_secondary*norm*256);
    font-&gt;<a class="code" href="structtexture__font__t.html#a6d2347450ec91e7148d211b21aed05d4" title="LCD filter weights.">lcd_weights</a>[4] = (<span class="keywordtype">unsigned</span> char)(p_tertiary*norm*256);

    <a name="a33"></a><a class="code" href="group__texture-font.html#ga912b65dd3d45ced38640cdfbecbb51c5" title="Request the loading of several glyphs at once.">texture_font_load_glyphs</a>( font, 
                              L<span class="stringliteral">&quot; !\&quot;#$%&amp;&#39;()*+,-./0123456789:;&lt;=&gt;?&quot;</span>
                              L<span class="stringliteral">&quot;@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_&quot;</span>
                              L<span class="stringliteral">&quot;`abcdefghijklmnopqrstuvwxyz{|}~&quot;</span> );
    pen.<a class="code" href="unionvec2.html#a002d3519d48fe3cd79729b5b0ded74bf" title="Alias for first component.">x</a> = 10;
    pen.<a class="code" href="unionvec2.html#a6d28b12b511da692550fc9d37b4e9b1d" title="Alias for second component.">y</a> = 600 - font-&gt;<a name="a34"></a><a class="code" href="structtexture__font__t.html#a8bd92ddb4c8e456aac6a21f6c268b360" title="This field is simply used to compute a default line spacing (i.e., the baseline-to-baseline distance)...">height</a> - 10;

    glyph = <a name="a35"></a><a class="code" href="group__texture-font.html#ga06e988448ef6e118aa6e273df5892937" title="Request a new glyph from the font.">texture_font_get_glyph</a>( font, text[0] );
    add_glyph( glyph, buffer, &amp;markup, &amp;pen, 0 );
    <span class="keywordflow">for</span>( i=1; i&lt;wcslen(text); ++i )
    {
        <span class="keywordflow">if</span>( text[i] == <span class="charliteral">&#39;\n&#39;</span> )
        {
            pen.<a class="code" href="unionvec2.html#a002d3519d48fe3cd79729b5b0ded74bf" title="Alias for first component.">x</a>  = 10;
            pen.<a class="code" href="unionvec2.html#a6d28b12b511da692550fc9d37b4e9b1d" title="Alias for second component.">y</a> -= font-&gt;<a class="code" href="structtexture__font__t.html#a8bd92ddb4c8e456aac6a21f6c268b360" title="This field is simply used to compute a default line spacing (i.e., the baseline-to-baseline distance)...">height</a>; <span class="comment">// + 0.01*(size - (int)size)*font-&gt;height;</span>
        }
        <span class="keywordflow">else</span>
        {
            glyph = <a class="code" href="group__texture-font.html#ga06e988448ef6e118aa6e273df5892937" title="Request a new glyph from the font.">texture_font_get_glyph</a>( font, text[i] );
            <span class="keywordtype">float</span> kerning = 0.0;
            <span class="keywordflow">if</span>( p_kerning )
            {
                kerning = <a name="a36"></a><a class="code" href="group__texture-font.html#ga77d1adb569e7eaa4aaf776dc28415c66" title="Get the kerning between two horizontal glyphs.">texture_glyph_get_kerning</a>( glyph, text[i-1] );
            }
            add_glyph( glyph, buffer, &amp;markup, &amp;pen, kerning );
        }
    }

    <a name="a37"></a><a class="code" href="group__texture-font.html#gaa894ab1def90197eaad58b578e7a2440" title="Delete a texture font.">texture_font_delete</a> (font );
}



<span class="comment">// ---------------------------------------------------------------- display ---</span>
<span class="keywordtype">void</span> display(<span class="keywordtype">void</span>)
{
    <span class="keywordflow">if</span>( p_invert )
    {
        glClearColor( 0, 0, 0, 1 );
    }
    <span class="keywordflow">else</span>
    {
        glClearColor( 1, 1, 1, 1 );
    }
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, atlas-&gt;<a name="a38"></a><a class="code" href="structtexture__atlas__t.html#a03e72bd01b6e5e97c0cc032d22c11c45" title="Texture identity (OpenGL)">id</a> );
    <span class="keywordflow">if</span>( !p_lcd_filtering )
    {
        glEnable( GL_COLOR_MATERIAL );
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        <span class="keywordflow">if</span>( p_invert )
        {
            glColor4f(1,1,1,1);
        }
        <span class="keywordflow">else</span>
        {
            glColor4f(0,0,0,1);
        }
    }
    <span class="keywordflow">else</span>
    {
        glEnable( GL_COLOR_MATERIAL );
        glBlendFunc( GL_CONSTANT_COLOR_EXT,
                     GL_ONE_MINUS_SRC_COLOR );
        glEnable( GL_BLEND );
        glColor3f( 1,1,1 );
        <span class="keywordflow">if</span>( p_invert )
        {
            glBlendColor( 1, 1, 1, 1 );
        }
        <span class="keywordflow">else</span>
        {
            glBlendColor( 0, 0, 0, 1 );
        }
    }

    <span class="keywordflow">if</span>( !p_lcd_filtering )
    {
        <a name="a39"></a><a class="code" href="group__vertex-buffer.html#ga48df5bafd9315aabfb7f14bedb778c16" title="Render vertex buffer.">vertex_buffer_render</a>( buffer, GL_TRIANGLES, <span class="stringliteral">&quot;vt&quot;</span> );
    }
    <span class="keywordflow">else</span>
    {
        glUseProgram( program );
        glUniform1i( texture_location, 0 );
        glUniform1f( gamma_location, p_gamma );

        <span class="keywordtype">float</span> norm = 1.0/(p_primary+2*p_secondary+2*p_tertiary);
        glUniform1f( primary_location,   p_primary*norm );
        glUniform1f( secondary_location, p_secondary*norm );
        glUniform1f( tertiary_location,  p_tertiary*norm );
        glUniform2f( pixel_location,
                     1.0/atlas-&gt;<a name="a40"></a><a class="code" href="structtexture__atlas__t.html#aa1fb802d48b70dc43e06e88f55f986aa" title="Width (in pixels) of the underlying texture.">width</a>,
                     1.0/atlas-&gt;<a name="a41"></a><a class="code" href="structtexture__atlas__t.html#a724b0e35c619f88b231eba83c39095cb" title="Height (in pixels) of the underlying texture.">height</a> );
        <a class="code" href="group__vertex-buffer.html#ga48df5bafd9315aabfb7f14bedb778c16" title="Render vertex buffer.">vertex_buffer_render</a>( buffer, GL_TRIANGLES, <span class="stringliteral">&quot;vtc&quot;</span> );
        glUseProgram( 0 );
    }

    TwDraw( );
    glutSwapBuffers( );
}


<span class="comment">// ---------------------------------------------------------------- reshape ---</span>
<span class="keywordtype">void</span> reshape( <span class="keywordtype">int</span> width, <span class="keywordtype">int</span> height )
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, 0, height, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    TwWindowSize( width, height );
}


<span class="comment">// ------------------------------------------------------------------- quit ---</span>
<span class="keywordtype">void</span> reset( <span class="keywordtype">void</span> )
{ 
    p_family    = VERA;
    p_size      = 12.0;
    p_invert    = 0;
    p_kerning   = 1;
    p_hinting   = 1;
    p_lcd_filtering = 1;
    p_gamma     = 1.0;
    p_interval  = 0.0;
    p_weight    = 0.33;
    p_width     = 1.0;
    p_faux_weight = 0.0;
    p_faux_italic = 0.0;

    <span class="comment">// FT_LCD_FILTER_LIGHT</span>
    p_primary   = 1.0/3.0;
    p_secondary = 1.0/3.0;
    p_tertiary  = 0.0/3.0;

    <span class="comment">// FT_LCD_FILTER_DEFAULT</span>
    <span class="comment">// p_primary   = 3.0/9.0;</span>
    <span class="comment">// p_secondary = 2.0/9.0;</span>
    <span class="comment">// p_tertiary  = 1.0/9.0;</span>

    <span class="keywordflow">if</span>( !p_lcd_filtering )
    {
        atlas = atlas_gray;
    }
    <span class="keywordflow">else</span>
    {
        atlas = atlas_rgb;
    }
    build_buffer();
}

<span class="comment">// ------------------------------------------------------------------- quit ---</span>
<span class="keywordtype">void</span> quit( <span class="keywordtype">void</span> )
{ 
    exit( EXIT_SUCCESS );
}

<span class="comment">// -------------------------------------------------------------- terminate ---</span>
<span class="keywordtype">void</span> terminate( <span class="keywordtype">void</span> )
{ 
    TwTerminate();
}

<span class="keywordtype">void</span> timer( <span class="keywordtype">int</span> fps )
{
    glutPostRedisplay();
    glutTimerFunc( 1000.0/fps, timer, fps );
}

<span class="comment">// --------------------------------------------------------- get/set invert ---</span>
<span class="keywordtype">void</span> TW_CALL set_invert( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_invert = *(<span class="keyword">const</span> <span class="keywordtype">int</span> *) value;
}
<span class="keywordtype">void</span> TW_CALL get_invert( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">int</span> *)value = p_invert;
}

<span class="comment">// -------------------------------------------------------- get/set kerning ---</span>
<span class="keywordtype">void</span> TW_CALL set_kerning( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_kerning = *(<span class="keyword">const</span> <span class="keywordtype">int</span> *) value;
    build_buffer();
}
<span class="keywordtype">void</span> TW_CALL get_kerning( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">int</span> *)value = p_kerning;
}

<span class="comment">// -------------------------------------------------------- get/set hinting ---</span>
<span class="keywordtype">void</span> TW_CALL set_hinting( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_hinting = *(<span class="keyword">const</span> <span class="keywordtype">int</span> *) value;
    build_buffer();
}
<span class="keywordtype">void</span> TW_CALL get_hinting( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">int</span> *)value = p_hinting;
}

<span class="comment">// -------------------------------------------------- get/set lcd_filtering ---</span>
<span class="keywordtype">void</span> TW_CALL set_lcd_filtering( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_lcd_filtering = *(<span class="keyword">const</span> <span class="keywordtype">int</span> *) value;
    <span class="keywordflow">if</span>( p_lcd_filtering )
    {
        atlas = atlas_rgb;
    }
    <span class="keywordflow">else</span>
    {
        atlas = atlas_gray;
    }
    build_buffer();
}
<span class="keywordtype">void</span> TW_CALL get_lcd_filtering( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">int</span> *)value = p_lcd_filtering;
}

<span class="comment">// --------------------------------------------------------- get/set weight ---</span>
<span class="keywordtype">void</span> TW_CALL set_weight( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_weight = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
}
<span class="keywordtype">void</span> TW_CALL get_weight( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_weight;
}

<span class="comment">// ---------------------------------------------------------- get/set gamma ---</span>
<span class="keywordtype">void</span> TW_CALL set_gamma( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_gamma = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
}
<span class="keywordtype">void</span> TW_CALL get_gamma( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
   *(<span class="keywordtype">float</span> *)value = p_gamma;
}

<span class="comment">// ---------------------------------------------------------- get/set width ---</span>
<span class="keywordtype">void</span> TW_CALL set_width( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_width = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
    build_buffer();
}
<span class="keywordtype">void</span> TW_CALL get_width( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_width;
}

<span class="comment">// ------------------------------------------------------- get/set interval ---</span>
<span class="keywordtype">void</span> TW_CALL set_interval( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_interval = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
    build_buffer();
}
<span class="keywordtype">void</span> TW_CALL get_interval( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_interval;
}

<span class="comment">// ---------------------------------------------------- get/set faux_weight ---</span>
<span class="keywordtype">void</span> TW_CALL set_faux_weight( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_faux_weight = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
}
<span class="keywordtype">void</span> TW_CALL get_faux_weight( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_faux_weight;
}

<span class="comment">// ---------------------------------------------------- get/set faux_italic ---</span>
<span class="keywordtype">void</span> TW_CALL set_faux_italic( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_faux_italic = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
    build_buffer();
}
<span class="keywordtype">void</span> TW_CALL get_faux_italic( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_faux_italic;
}

<span class="comment">// ----------------------------------------------------------- get/set size ---</span>
<span class="keywordtype">void</span> TW_CALL set_size( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_size = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
    build_buffer();

}
<span class="keywordtype">void</span> TW_CALL get_size( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_size;
}

<span class="comment">// --------------------------------------------------------- get/set family ---</span>
<span class="keywordtype">void</span> TW_CALL set_family( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_family = *(<span class="keyword">const</span> font_family_e *) value;
    build_buffer();
}
<span class="keywordtype">void</span> TW_CALL get_family( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(font_family_e *)value = p_family;
}

<span class="comment">// ----------------------------------------------------------- get/set primary ---</span>
<span class="keywordtype">void</span> TW_CALL set_primary( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_primary = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
    build_buffer();

}
<span class="keywordtype">void</span> TW_CALL get_primary( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_primary;
}

<span class="comment">// ----------------------------------------------------------- get/set secondary ---</span>
<span class="keywordtype">void</span> TW_CALL set_secondary( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_secondary = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
    build_buffer();

}
<span class="keywordtype">void</span> TW_CALL get_secondary( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_secondary;
}

<span class="comment">// ----------------------------------------------------------- get/set tertiary ---</span>
<span class="keywordtype">void</span> TW_CALL set_tertiary( <span class="keyword">const</span> <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    p_tertiary = *(<span class="keyword">const</span> <span class="keywordtype">float</span> *) value;
    build_buffer();

}
<span class="keywordtype">void</span> TW_CALL get_tertiary( <span class="keywordtype">void</span> *value, <span class="keywordtype">void</span> *data )
{
    *(<span class="keywordtype">float</span> *)value = p_tertiary;
}
 

<span class="comment">// Main</span>
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
{
    glutInit( &amp;argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutInitWindowSize( 800, 600 );
    glutCreateWindow( <span class="stringliteral">&quot;Font rendering advanced tweaking&quot;</span> );
    glutCreateMenu( NULL );


    glutDisplayFunc( display );
    glutReshapeFunc( reshape );
    atexit( terminate );
    TwInit( TW_OPENGL, NULL );
    glutMouseFunc( (GLUTmousebuttonfun)TwEventMouseButtonGLUT );
    glutMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT );
    glutPassiveMotionFunc( (GLUTmousemotionfun)TwEventMouseMotionGLUT );
    glutKeyboardFunc( (GLUTkeyboardfun)TwEventKeyboardGLUT );
    glutSpecialFunc( (GLUTspecialfun)TwEventSpecialGLUT );
    TwGLUTModifiersFunc( glutGetModifiers );

    <span class="comment">// Create a new tweak bar</span>
    bar = TwNewBar(<span class="stringliteral">&quot;TweakBar&quot;</span>);
    TwDefine(<span class="stringliteral">&quot;GLOBAL &quot;</span>
             <span class="stringliteral">&quot;help = &#39;This example shows how to tune all font parameters.&#39; &quot;</span>);
    TwDefine(<span class="stringliteral">&quot;TweakBar                      &quot;</span>
             <span class="stringliteral">&quot;size          = &#39;280 400&#39;     &quot;</span>
             <span class="stringliteral">&quot;position      = &#39;500 20&#39;      &quot;</span>
             <span class="stringliteral">&quot;color         = &#39;127 127 127&#39; &quot;</span>
             <span class="stringliteral">&quot;alpha         = 240           &quot;</span>
             <span class="stringliteral">&quot;label         = &#39;Parameters&#39;  &quot;</span>
             <span class="stringliteral">&quot;resizable     = True          &quot;</span>
             <span class="stringliteral">&quot;fontresizable = True          &quot;</span>
             <span class="stringliteral">&quot;iconifiable   = True          &quot;</span>);

    {
        TwEnumVal familyEV[NUM_FONTS] = {
            {VERA,      <span class="stringliteral">&quot;Vera&quot;</span>},
            {VERA_MONO, <span class="stringliteral">&quot;Vera Mono&quot;</span>},
            {GEORGIA,   <span class="stringliteral">&quot;Georgia&quot;</span>},
            {TIMES,     <span class="stringliteral">&quot;Times&quot;</span>},
            {VERDANA,   <span class="stringliteral">&quot;Verdana&quot;</span>},
            {TAHOMA,    <span class="stringliteral">&quot;Tahoma&quot;</span>},
            {ARIAL,     <span class="stringliteral">&quot;Arial&quot;</span>} };
        TwType family_type = TwDefineEnum(<span class="stringliteral">&quot;Family&quot;</span>, familyEV, NUM_FONTS);
        TwAddVarCB(bar, <span class="stringliteral">&quot;Family&quot;</span>, family_type, set_family, get_family, NULL, 
                   <span class="stringliteral">&quot;label = &#39;Family&#39;      &quot;</span>
                   <span class="stringliteral">&quot;group = &#39;Font&#39;        &quot;</span>
                   <span class="stringliteral">&quot;help  = &#39; &#39;           &quot;</span>);
    }
    TwAddVarCB(bar, <span class="stringliteral">&quot;Size&quot;</span>, TW_TYPE_FLOAT, set_size, get_size, NULL, 
               <span class="stringliteral">&quot;label = &#39;Size&#39; &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Font&#39; &quot;</span>
               <span class="stringliteral">&quot;min   = 6.0    &quot;</span>
               <span class="stringliteral">&quot;max   = 24.0   &quot;</span>
               <span class="stringliteral">&quot;step  = 0.05   &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;    &quot;</span>);
    TwAddVarCB(bar, <span class="stringliteral">&quot;LCD filtering&quot;</span>, TW_TYPE_BOOL32, set_lcd_filtering, get_lcd_filtering, NULL, 
               <span class="stringliteral">&quot;label = &#39;LCD filtering&#39; &quot;</span>
              <span class="stringliteral">&quot;group = &#39;Font&#39;        &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;             &quot;</span>);


    <span class="comment">// Rendering</span>
    TwAddVarCB(bar, <span class="stringliteral">&quot;Kerning&quot;</span>, TW_TYPE_BOOL32, set_kerning, get_kerning, NULL, 
               <span class="stringliteral">&quot;label = &#39;Kerning&#39;   &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Rendering&#39; &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;         &quot;</span>);
    TwAddVarCB(bar, <span class="stringliteral">&quot;Hinting&quot;</span>, TW_TYPE_BOOL32, set_hinting, get_hinting, NULL, 
               <span class="stringliteral">&quot;label = &#39;Hinting&#39;   &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Rendering&#39; &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;         &quot;</span>);

    <span class="comment">// Color</span>
    TwAddVarCB(bar, <span class="stringliteral">&quot;Invert&quot;</span>, TW_TYPE_BOOL32, set_invert, get_invert, NULL, 
               <span class="stringliteral">&quot;label = &#39;Invert&#39; &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Color&#39;  &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;      &quot;</span>);
    
    <span class="comment">// Glyph</span>
    TwAddVarCB(bar, <span class="stringliteral">&quot;Width&quot;</span>, TW_TYPE_FLOAT, set_width, get_width, NULL, 
               <span class="stringliteral">&quot;label = &#39;Width&#39; &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Glyph&#39; &quot;</span>
               <span class="stringliteral">&quot;min   = 0.75    &quot;</span>
               <span class="stringliteral">&quot;max   = 1.25    &quot;</span> 
               <span class="stringliteral">&quot;step  = 0.01    &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;     &quot;</span>);

    TwAddVarCB(bar, <span class="stringliteral">&quot;Interval&quot;</span>, TW_TYPE_FLOAT, set_interval, get_interval, NULL, 
               <span class="stringliteral">&quot;label = &#39;Spacing&#39; &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Glyph&#39;   &quot;</span>
               <span class="stringliteral">&quot;min   = -0.2      &quot;</span>
               <span class="stringliteral">&quot;max   = 0.2       &quot;</span>
               <span class="stringliteral">&quot;step  = 0.01      &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;       &quot;</span> );

    TwAddVarCB(bar, <span class="stringliteral">&quot;Faux italic&quot;</span>, TW_TYPE_FLOAT, set_faux_italic, get_faux_italic, NULL, 
               <span class="stringliteral">&quot;label = &#39;Faux italic&#39; &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Glyph&#39;       &quot;</span>
               <span class="stringliteral">&quot;min   = -30.0         &quot;</span>
               <span class="stringliteral">&quot;max   =  30.0         &quot;</span>
               <span class="stringliteral">&quot;step  = 0.1           &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;           &quot;</span>);

    <span class="comment">// Energy distribution</span>
    TwAddVarCB(bar, <span class="stringliteral">&quot;Primary&quot;</span>, TW_TYPE_FLOAT, set_primary, get_primary, NULL,
               <span class="stringliteral">&quot;label = &#39;Primary weight&#39;      &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Energy distribution&#39; &quot;</span>
               <span class="stringliteral">&quot;min   = 0                     &quot;</span>
               <span class="stringliteral">&quot;max   = 1                     &quot;</span>
               <span class="stringliteral">&quot;step  = 0.01                  &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;                   &quot;</span> );

    TwAddVarCB(bar, <span class="stringliteral">&quot;Secondary&quot;</span>, TW_TYPE_FLOAT, set_secondary, get_secondary, NULL,
               <span class="stringliteral">&quot;label = &#39;Secondy weight&#39;      &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Energy distribution&#39; &quot;</span>
               <span class="stringliteral">&quot;min   = 0                     &quot;</span>
               <span class="stringliteral">&quot;max   = 1                     &quot;</span>
               <span class="stringliteral">&quot;step  = 0.01                  &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;                   &quot;</span> );

    TwAddVarCB(bar, <span class="stringliteral">&quot;Tertiary&quot;</span>, TW_TYPE_FLOAT, set_tertiary, get_tertiary, NULL,
               <span class="stringliteral">&quot;label = &#39;Tertiary weight&#39;      &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Energy distribution&#39; &quot;</span>
               <span class="stringliteral">&quot;min   = 0                     &quot;</span>
               <span class="stringliteral">&quot;max   = 1                     &quot;</span>
               <span class="stringliteral">&quot;step  = 0.01                  &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;                   &quot;</span> );

    TwAddSeparator(bar, <span class="stringliteral">&quot;&quot;</span>,
                   <span class="stringliteral">&quot;group = &#39;Energy distribution&#39; &quot;</span> );

    TwAddVarCB(bar, <span class="stringliteral">&quot;Gamma&quot;</span>, TW_TYPE_FLOAT, set_gamma, get_gamma, NULL, 
               <span class="stringliteral">&quot;label = &#39;Gamma correction&#39;    &quot;</span>
               <span class="stringliteral">&quot;group = &#39;Energy distribution&#39; &quot;</span>
               <span class="stringliteral">&quot;min   = 0.50                  &quot;</span>
               <span class="stringliteral">&quot;max   = 2.5                   &quot;</span>
               <span class="stringliteral">&quot;step  = 0.01                  &quot;</span>
               <span class="stringliteral">&quot;help  = &#39; &#39;                   &quot;</span>);

    TwAddSeparator(bar, <span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;&quot;</span>);
    TwAddButton(bar, <span class="stringliteral">&quot;Reset&quot;</span>, (TwButtonCallback) reset, NULL,
                <span class="stringliteral">&quot;help=&#39;Reset all parameters to default values.&#39;&quot;</span>);
    TwAddSeparator(bar, <span class="stringliteral">&quot;&quot;</span>, <span class="stringliteral">&quot;&quot;</span>);
    TwAddButton(bar, <span class="stringliteral">&quot;Quit&quot;</span>, (TwButtonCallback) quit, NULL,
                <span class="stringliteral">&quot;help=&#39;Quit.&#39;&quot;</span>);

    atlas_gray = <a name="a42"></a><a class="code" href="group__texture-atlas.html#ga7769be70f630e0a8a8b320525a07382d" title="Creates a new empty texture atlas.">texture_atlas_new</a>( 512, 256, 1 );
    atlas_rgb  = <a class="code" href="group__texture-atlas.html#ga7769be70f630e0a8a8b320525a07382d" title="Creates a new empty texture atlas.">texture_atlas_new</a>( 512, 256, 3 );
    buffer = <a name="a43"></a><a class="code" href="group__vertex-buffer.html#ga309c1129a1028f251fe6e6c3c1534a42" title="Creates an empty vertex buffer.">vertex_buffer_new</a>( <span class="stringliteral">&quot;v3f:t2f:c4f:1g1f&quot;</span> ); 
    reset();

    <span class="comment">// Create the shader</span>
    program = <a name="a44"></a><a class="code" href="group__shader.html#ga2b7a0078428da8b7fd08b17b498de7f3" title="Load a vertex and fragment shader sources and build program.">shader_load</a>( <span class="stringliteral">&quot;shaders/agg.vert&quot;</span>,
                           <span class="stringliteral">&quot;shaders/agg.frag&quot;</span> );
    texture_location = glGetUniformLocation( program, <span class="stringliteral">&quot;texture&quot;</span> );
    pixel_location = glGetUniformLocation( program, <span class="stringliteral">&quot;pixel&quot;</span> );
    gamma_location = glGetUniformLocation( program, <span class="stringliteral">&quot;gamma&quot;</span> );
    primary_location   = glGetUniformLocation( program, <span class="stringliteral">&quot;primary&quot;</span> );
    secondary_location = glGetUniformLocation( program, <span class="stringliteral">&quot;secondary&quot;</span> );
    tertiary_location  = glGetUniformLocation( program, <span class="stringliteral">&quot;tertiary&quot;</span> );
    <span class="comment">//glEnable(GL_FRAMEBUFFER_SRGB);</span>
    glutTimerFunc( 1000.0/60.0, timer, 60 );
    glutMainLoop();
    <span class="keywordflow">return</span> EXIT_SUCCESS;
}

</pre></div> </div><!-- contents -->
</div>
</body>
</html>
